package com.lyf.common.serialize;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author lyf
 * @since 2021/3/13 11:49
 */
public class SerializeMinuteStamp extends JsonSerializer<Long> {

    @Override
    public void serialize(Long timeStamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String timeStr = format.format(new Date(Long.valueOf(timeStamp / 1000 +"000")));
        jsonGenerator.writeString(timeStr);
    }
}
